package io.bsly.config.redisConfig;

import io.bsly.common.utils.Constant;
import io.bsly.modules.platform.api.douDianApi.DouDianApi;
import io.bsly.modules.platform.api.douDianApi.DoudianHttpUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DouDianTokenExpirationListerner extends KeyExpirationEventMessageListener {
    @Autowired
    DouDianApi douDianApi;
    @Autowired
    private RedisTemplate redisTemplate;

    public DouDianTokenExpirationListerner(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern)   {
        String keyExpira = message.toString();
        /**
         * key : doudian:token:accessToken
         */
        if (keyExpira.equals(Constant.DOUDIAN_ACCESS_TOKEN_BEAN)){
            System.out.println("key 过期======>>>>>>"+keyExpira);
            douDianApi.refreshToken();
        }
    }
}
